package com.zhang.study.chapter03;

/**
 * 在一个长度为 N 的数组中，求最大值
 * 递归
 */
public class Code11_GetMax {

    public static int getMax(int[] arr) {
        if (arr == null || arr.length == 0) {
            return -1;
        }
        return process(arr, 0, arr.length - 1);
    }


    public static int process(int[] arr, int start, int end) {
        if (start == end) {
            return arr[start];
        }
        // int mid = (start + end) / 2;
        int mid = start + ((end - start) >> 1);
        int left = process(arr, start, mid);
        int right = process(arr, mid + 1, end);
        return Math.max(left, right);
    }

    public static int process2(int[] arr, int start, int end) {
        if (start == end) {
            return arr[start];
        }
        // int mid = (start + end) / 2;
        for (int i = 0; i < arr.length; i++) {
            System.out.println("啥也不干,就是输出！");
        }
        int mid = start + ((end - start) >> 1);
        int left = process(arr, start, mid);
        int right = process(arr, mid + 1, end);
        return Math.max(left, right);
    }


}
